#include "./include/cyrobot_monitor/form.h"
#include "ui_form.h"
#include <QMessageBox>
#include<QFile>
Form::Form(QWidget *parent) :
  QWidget(parent),
  ui(new Ui::Form)
{
  ui->setupUi(this);

}

Form::~Form()
{
  delete ui;
}

void Form::on_pushbutton_clicked()
{
  if(ui->pushbutton->text() == tr("确认路径选取")){
    //QString path = QString("/home/l/test_ws/src/common/file/waypoint/%1.csv").arg(ui->comboBox->currentIndex()+1);
    QString path = QString("%2/%1.csv").arg(ui->comboBox->currentIndex()+1).arg(path1.csv_pos_file_path);
    QFile file(path);
    if(file.exists()){
      emit fasong_lujing(ui->comboBox->currentIndex()+1);
      this->hide();
    }
    else{
      QString maomao = QString("没有路径%1").arg(ui->comboBox->currentIndex()+1);
      QMessageBox::warning(NULL,"选择失败",maomao,QMessageBox::Ok);
    }

  }
  else if(ui->pushbutton->text() == tr("确认路径保存")){
    QString maomao = QString("当前文件已存在路径%1,是否重新覆盖").arg(ui->comboBox->currentIndex()+1);
    QString path = QString("%2/%1.csv").arg(ui->comboBox->currentIndex()+1).arg(path1.csv_pos_file_path);
    QFile file(path);
    if(file.exists()){
      QMessageBox::StandardButtons result = QMessageBox::warning(NULL,"重复创建",maomao,QMessageBox::Yes|QMessageBox::No);
      if(result == QMessageBox::Yes){
        emit fasong_csv(ui->comboBox->currentIndex()+1,true);
        this->hide();
      }
      else{

      }
    }
    else{
      emit fasong_csv(ui->comboBox->currentIndex()+1,true);
      this->hide();
    }

  }
}

void Form::change_name(QString maotian){
   ui->pushbutton->setText(maotian);
}
